using System;
using System.Collections.Generic;
using System.Text;
using DTOLayer;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace DAOLayer
{
    public class DAOMonHoc:DataProvider
    {
        public DAOMonHoc()
        {
        }
        public DataTable LayDanhSachMonHoc()
        {
            connect();
            SqlCommand cmd = new SqlCommand("sp_Select_MonHocChiTiet", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            disconnect();
            return ds.Tables[0];

        }
        public ArrayList LayMang_MonHoc()
        {
            connect();
            ArrayList arr = new ArrayList();
            try
            {
                SqlCommand cmd = new SqlCommand("sp_Select_MonHoc", strCnn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    DTOMonHoc mondto = new DTOMonHoc();
                    mondto.MaMonHoc = dr.GetString(0);
                    mondto.TenMon = dr.GetString(1);
                    mondto.SoTinChi = dr.GetInt32(2);
                    mondto.DeCuong = dr.GetString(3);
                    mondto.MaLoai = dr.GetInt32(4);
                    mondto.MaBoMon = dr.GetInt32(5);
                    arr.Add(mondto);
                }


            }
            catch (Exception es)
            {
                throw es;
            }
            disconnect();
            return arr;
        }
      
        public string insert(DTOMonHoc mondto)
        {
            connect();
            string Ma = "";
            try
            {
                SqlCommand cmd = new SqlCommand("sp_Insert_MonHoc", strCnn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@tenMon", SqlDbType.NVarChar);
                cmd.Parameters["@tenMon"].Value = mondto.TenMon.ToString();

                cmd.Parameters.Add("@soTinChi", SqlDbType.Int);
                cmd.Parameters["@soTinChi"].Value = mondto.SoTinChi;

                cmd.Parameters.Add("@deCuong", SqlDbType.NVarChar);
                cmd.Parameters["@deCuong"].Value = mondto.DeCuong.ToString();

                cmd.Parameters.Add("@maLoai", SqlDbType.Int);
                cmd.Parameters["@maLoai"].Value = mondto.MaLoai;

                cmd.Parameters.Add("@maBoMon", SqlDbType.Int);
                cmd.Parameters["@maBoMon"].Value = mondto.MaBoMon;

                cmd.Parameters.Add("@maMonHoc", SqlDbType.Int);
                cmd.Parameters["@maMonHoc"].Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();
                Ma = cmd.Parameters["@maMonHoc"].Value.ToString();
                
               
            }
            catch (Exception es)
            {
                throw es;
            }
            disconnect();
            return Ma;
        }

        public void delete(string mamon)
        {
            connect();
            try
            {
                SqlCommand cmd = new SqlCommand("sp_Delete_MonHoc", strCnn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@maMonHoc", SqlDbType.NVarChar);
                cmd.Parameters["@maMonHoc"].Value = mamon;
                cmd.ExecuteNonQuery();

            }
            catch (Exception es)
            {
                throw es;
            }
            disconnect();
        }

        public void update(DTOMonHoc mondto)
        {
            connect();
            try
            {
                SqlCommand cmd = new SqlCommand("sp_Update_TaiKhoan", strCnn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@tenMon", SqlDbType.NVarChar);
                cmd.Parameters["@tenMon"].Value = mondto.TenMon.ToString();

                cmd.Parameters.Add("@soTinChi", SqlDbType.Int);
                cmd.Parameters["@soTinChi"].Value = mondto.SoTinChi;

                cmd.Parameters.Add("@deCuong", SqlDbType.NVarChar);
                cmd.Parameters["@deCuong"].Value = mondto.DeCuong.ToString();

                cmd.Parameters.Add("@maLoai", SqlDbType.Int);
                cmd.Parameters["@maLoai"].Value = mondto.MaLoai;

                cmd.Parameters.Add("@maBoMon", SqlDbType.Int);
                cmd.Parameters["@maBoMon"].Value = mondto.MaBoMon;

                cmd.Parameters.Add("@maMonHoc", SqlDbType.Int);
                cmd.Parameters["@maMonHoc"].Value = mondto.MaBoMon;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            disconnect();
        }
    }
}
